﻿@model IEnumerable<Scap.Info.ScapDepartment>

<div id="@ViewBag.MainDiv">
    <div class="sfactive">Empleados -> Definir Departamento</div>
    <div style="margin-bottom: 5px; margin-top: 5px;">
        @Html.ActionLink("Añadir Departamento", "AddDepartamento", "tabsDepartamento", new { id = "0" }, new { id = "lnkadicionaDepartamentoTabsDeptoid" })
    </div>
    <div style="width: 100%; border: 1px solid #808080; margin-top: 5px; margin-bottom: 5px; padding: 5px;">
        @using (Html.BeginForm("Index", "tabsDepartamento", null, FormMethod.Post, new { id = "formsearchDeptoidid" }))
        {
            <div class="tblvios02">
                <table style="width: 900px;">
                    <tr>
                        <td class="editor-label">Nombre</td>
                        <td class="vios160">
                            <input id="nombredeptoid" name="nombredeptoid" type="text" /></td>
                        <td class="editor-label">Descripcion</td>
                        <td class="vios160">
                            <input id="descripciondeptoid" name="descripciondeptoid" type="text" /></td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: right;">
                            <div style="display: block">
                                <input class="btSubmitBuscarDeptoArea" id="SubmitDepartamentoSearch" type="submit" value="Buscar" />
                            </div>
                            <div class="viosbox" id="waitDocumentiImage" style="display: none; text-align: center;">
                                <img alt="Loading" src="@Url.Content("~/Images/ajaxanim.gif")" />&nbsp;<span>Cargando ...</span>
                            </div>
                        </td>
                        <td>@Html.ActionLink("Avanzada", "Index", "Employee", null, null)</td>
                        <td>@Html.ActionLink("Ver Todo", "Index", "Employee", null, null)</td>
                    </tr>
                </table>
            </div> 
        }
    </div>
    <div style="border: 0px solid #FF6600;">
        <div class="float-right" style="border: 1px solid #CCCC00; width: 340px; margin-left: 8px;">
            <div id="mostrararbolId" style="border: 0px solid #CCCC00; margin: 5px; padding: 5px; display: block;">
                @*                <div id="treeDeptoid" class="aciTree">
                </div>*@
            </div>
        </div>
        <div style="width: 60%; border: 1px solid #808080; margin-top: 5px; margin-bottom: 5px; padding: 5px;">
            <table class="webgrid" style="width: 100%;">
                <tr>
                    <th></th>
                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Description)
                    </th>
                    <th>
                        @*Html.DisplayNameFor(model => model.ParentDepartment.Name)*@
                        Departamento Padre
                    </th>
                </tr>
                @{
                    int nRow = 0;
                    int nMod = 0;
                    int nParentID = 0;
                    string szClass = "";
                    string szParentName = "";
                    Scap.Web.Controllers.tabsDepartamentoController tabDepto = new Scap.Web.Controllers.tabsDepartamentoController();

                }

                @foreach (var item in Model)
                {
                    nRow++;
                    nMod = (nRow % 2);
                    if (nMod == 0)
                    {
                        szClass = "webgrid-alternating-row";
                    }
                    else
                    {
                        szClass = "webgrid-row-style";
                    }
                    <tr class="@szClass">
                        <td>
                            <div class="editarDeptoLnk">
                                @Html.ActionLink("Editar", "EditDepartamento", "tabsDepartamento", new { id = item.Id }, null)
                            </div>
                            @Html.ActionLink("Borrar", "DeleteDepartamento", new { id = item.Id }, new { onclick = "return confirm('Esta seguro de borrar este departamento?');" })
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Name)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Description)
                        </td>
                        <td>
                            @*Html.DisplayFor(modelItem => item.TypeId)*@
                            @*Html.DisplayFor(modelItem => item.ParentDepartment.Name)*@
                            @if (item.ParentDepartmentId != null && item.ParentDepartment == null)
                            {
                                tabDepto.GetParentData(item.Name, ref szParentName, ref nParentID, item.TypeId);
                                if (szParentName != null)
                                {
                                    @szParentName
                                }
                            }
                            else
                            {
                               @Html.DisplayFor(modelItem => item.ParentDepartment.Name)     
                            }
                        </td>
                    </tr>
                }
                <tr>
                    <td colspan="4">
                    <table border="0" cellpadding="0" cellspacing="0" style="width: 95%">
                        <tr>
                            <td>
                                @{
                                    string szStyleHasPreviousPage = "display:none";
                                    string szStyleHasNextPage = "display:none";
                                    if (ViewBag.HasPreviousPage)
                                    {
                                        szStyleHasPreviousPage = "display:block";
                                    }
                                    if (ViewBag.HasNextPage)
                                    {
                                        szStyleHasNextPage = "display:block";
                                    }
                                }
                                <div style="border: 0px solid #CCCC00;">
                                    <table class="tblvios" style="width: 60%">
                                        <tr>
                                            <td>Page @(ViewBag.PageCount < ViewBag.PageNumber ? 0 : ViewBag.PageNumber)
                                                of @ViewBag.PageCount</td>
                                            <td>
                                                <div style="@szStyleHasNextPage">
                                                    @using (Html.BeginForm("Index", "tabsDepartamento", new { page = ViewBag.PageNumber + 1, sortOrder = ViewBag.CurrentSort }, FormMethod.Post, new { @class = "deptoNavLnk" }))
                                                    {
                                                        <input class="btEmpleadoNav" id="nextSubmit1tbsEmpid" type="submit" value="Next" />
                                                    }
                                                </div>
                                            </td>
                                            <td>
                                                <div style="@szStyleHasNextPage">
                                                    @using (Html.BeginForm("Index", "tabsDepartamento", new { page = ViewBag.PageCount, sortOrder = ViewBag.CurrentSort }, FormMethod.Post, new { @class = "deptoNavLnk" }))
                                                    {
                                                        <input class="btEmpleadoNav" id="LastSubmit1tbsEmpid" type="submit" value="Last" />
                                                    }
                                                </div>
                                            </td>
                                            <td>
                                                <div style="@szStyleHasPreviousPage">
                                                    @using (Html.BeginForm("Index", "tabsDepartamento", new { page = 1, sortOrder = ViewBag.CurrentSort }, FormMethod.Post, new { @class = "deptoNavLnk" }))
                                                    {
                                                        <input class="btEmpleadoNav" id="FirstSubmit1tbsEmpid" type="submit" value="First" /> 
                                                    }
                                                </div>
                                            </td>
                                            <td>
                                                <div style="@szStyleHasPreviousPage">
                                                    @using (Html.BeginForm("Index", "tabsDepartamento", new { page = ViewBag.PageNumber - 1, sortOrder = ViewBag.CurrentSort }, FormMethod.Post, new { @class = "deptoNavLnk" }))
                                                    {
                                                        <input class="btEmpleadoNav" id="PrevSubmit1tbsEmpid" type="submit" value="Prev" /> 
                                                    }
                                                </div>
                                            </td>
                                        </tr>
                                    </table>

                                </div>
                            </td>
                            <td style="display: none">
                                @Html.ActionLink("Back", "Index")
                            </td>
                        </tr>
                    </table>
                    </td>
                </tr>

            </table>
        </div>
    </div>
</div>
